<?php
global $_GPC, $_W;
$uniacid = $_W['uniacid'];
$op = $_GPC['op'];
$openid = $_GPC['openid'];
$id = $_GPC['id'];
$res = $this->res;
$plus = $this->plus;
load()->model('mc');
load()->func('tpl');
$setting = $this->baseset($uniacid);
$settings = $this->module['config'];
$user = pdo_fetch("SELECT * FROM " . tablename($this->tableuser) . " WHERE uniacid = '{$_W['uniacid']}' AND openid = '{$openid}'");
if (!$user) {
	exit(json_encode(array('status' => '500')));
}
$total = pdo_fetchcolumn("SELECT COUNT(*) FROM " . tablename($this->tableuser) . " WHERE uniacid = '{$_W['uniacid']}' AND helpid = '{$user['uid']}' AND status=1");
if ($_W['ispost'] && $op == 'list') {
	$nowpage = $_GPC['limit'];
	$pindex = max(1, intval($nowpage));
	$psize = 10;
	$uid = mc_openid2uid($openid);
	$list0 = pdo_fetchall("SELECT * FROM " . tablename($this->tableuser) . " WHERE uniacid = :uniacid AND helpid=:helpid AND status = 1 LIMIT " . ($pindex - 1) * $psize . ',' . $psize, array(':uniacid' => $uniacid, ':helpid' => $uid));
	if ($list0) {
		foreach ($list0 as $key => $value) {
			$mcinfo = mc_fetch($list0[$key]['uid']);
			$list0[$key]['jifen'] = $mcinfo['credit1'];
			$list0[$key]['jinqian'] = $mcinfo['credit2'];
			$mc_data = array('credit1' => $list0[$key]['jifen'], 'credit2' => $list0[$key]['jinqian'],);
			pdo_update($this->tableuser, $mc_data, array('id' => $list0[$key]['id']));
		}
	}
	$list = pdo_fetchall("SELECT * FROM " . tablename($this->tableuser) . " WHERE uniacid = :uniacid AND helpid=:helpid AND status = 1 ORDER BY  credit1 DESC LIMIT " . ($pindex - 1) * $psize . ',' . $psize, array(':uniacid' => $uniacid, ':helpid' => $uid));
	if (!empty($list)) {
		foreach ($list as $key => $value) {
			$mcinfo = mc_fetch($list[$key]['uid']);
			$list[$key]['total'] = pdo_fetchcolumn("SELECT COUNT(*) FROM " . tablename($this->tableuser) . " WHERE uniacid = '{$_W['uniacid']}' AND helpid = '{$list[$key]['uid']}' AND status=1");
			if ($key < 3) {
				$list[$key]['hg'] = "hg1.gif";
				$list[$key]['item3color'] = 'style="color:#FC573D;"';
			} else {
				$list[$key]['hg'] = "hg2.gif";
			}
			$list[$key]['avatar'] = tomedia($list[$key]['avatar']);
			$list[$key]['jifen'] = $list[$key]['credit1'];
			$list[$key]['jinqian'] = $list[$key]['credit2'];
			$list[$key]['py2url'] = $this->createMobileUrl('uc_ph_py2', array('openid' => $list[$key]['openid']));;
		}
		$sta = 200;
	} else {
		$sta = -103;
	}
	exit(json_encode(array('status' => $sta, 'content' => $list)));
}
include $this->template('uc_ph_py2');